package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.io.Serializable;
import java.util.List;

@Mapper
public interface AddressBookMapper {
    /*
    * 新增地址
    * */
    void insert(AddressBook addressBook);

    /*
    * 查询当前登录用户的所有地址信息
    * */
    @Select("SELECT * FROM address_book WHERE user_id = #{userId}")
    List<AddressBook> selectListByUserId(Long userId);

    @Select("SELECT * FROM address_book WHERE user_id = #{userId} AND is_default = 1")
    AddressBook getDefaultAddressBook(Long userId);

    @Select("SELECT * FROM address_book WHERE id = #{id}")
    AddressBook getAddressByID(Long id);

    void updateAddressById(AddressBook addressBook);

    @Delete("DELETE FROM address_book WHERE id = #{id}")
    void deleteAddressBookById(Long id);
}
